# program InitRandom(seed) # Intitializes all random routines; seed ~ 1.0 .
# function Random # Returns a uniform random number between 0 and 1.
# function RandomArray(N) # Returns an array of N randoms.
# function RandomInRange(J,L) # Returns a random integer K, J<=K<=L
#
# function WhiteNoise(n) # Returns n-array of uniform, sigma=1 white noise.
# function GaussianNoise(N) # Returns array of gaussian noise, sigma=1.
# program MakeDistribution(Y,max,N, x,P) # Bin randoms y into a distribution P
#
# This text file explains and gives examples of
# some of the routines in the file All Library Routines, which
# should be Opened before trying any of these examples.
##################
##############
# The xCOD itself is
xRANDOM
# xCO2 xRANDOM(zInit,N,x:extended; RandStore:RealArray) , sets 0<x[1…N]<1 to random numbers. RandStore[1..100] must be preserved between calls. zInit <0 is a signal to initialize RandStore with zInit seed ; an external program.
############
# The interface routines.
# Examples are given after each.
# This must be called once, initially, with a 0-10 or so
# random seed. The storage array RandStore must
# exist between successive calls to xRANDOM.
program InitRandom(seed) # Intitializes all random routines; seed ~ 1.0 .
. var x
. # Input: seed = real random number ~ 1.0
. # Output: none. Sets up RandStore.
. begin
. RandStore[1…100] = 0
. x[1…2] = 0
. xRANDOM(-314159*seed, size(x),x,RandStore)
. end
.
# If you want a different set of 'randoms', use a different
# seed than the one here.
InitRandom(0.133241)
###########################
# Here a number of different uses of xRandom.
# Examples are given for each.
# This returns a single random number
# uniformly distributed from 0 to 1.
#
function Random # Returns a uniform random number between 0 and 1.
. var x
. # Input: none
. # Ouput: 0 < Random < 1
. begin
. x=0
. xRandom(1,1,x,RandStore)
. Random=x
. end
.
# For example,
Random # type this, hit return
0.70898038 # and get this the 1st time
Random
0.57992348 # but this the second.
# Returns an array of N random numbers between 0 and 1.
# Much faster than successive calls to Random, above.
#
function RandomArray(N) # Returns an array of N randoms.
. var x
. # Input: N = positive integer
. # Output: RandomArray = x[1…N] random numbers, all 0 -> 1.
. begin
. x[1…n]=0
. xRandom(1,n,x,RandStore)
. RandomArray = x
. end
.
# For example,
RandomArray(5)
[0.85127, 0.2307, 0.65812, 0.64353, 0.11952]
# Gives a random integer K in the range J <= K <= L.
# Note that the Int(x) function rounds to
# the nearest even integer.
#
function RandomInRange(J,L) # Returns a random integer K, J<=K<=L
. var x, a, b
. # Input: J, L = integers
. # Ouput: RandomInRange = random integer from J to L.